#include "ParamConstraintTest.h"
//CPPUNIT_TEST_SUITE_REGISTRATION (ParamConstraintTest);

void ParamConstraintTest::setUp(void) {
	x = 10;
	y = 20;
	id = 3;
	value = 23.03;
	param = new Parameter(id, value);

	val1 = new skreal(3);
	val2 = new skreal(1);

	p1 = new Point(1, x, y);
	p2 = new Point(2, y, x);
	p3 = new Point(3, 2 * x, 2 * y);
	p4 = new Point(4, 2 * y, 2 * x);


	con2point = new ConnectPoints(1, p1, p2);
	con = new ConnectPoints(2, p2, p2);
	cPer1 = new Perpendicular(3, p1, p2, p3, p4);
	cPer2 = new Perpendicular(4, p1, p2, new Vector(x, 2 * y), new Vector(y, 2 * x));

	cFix1 = new FixPoint(5,p1,new Vector(x,y));
	con2 = new FixPoint(6,p2,new Vector(*p2));
	cH1 = new Horizontal(7,p1,p3);
	cV1 = new Vertical(8,p2,p4);
}

void ParamConstraintTest::tearDown(void) {
	delete p1;
	delete p2;
	delete p3;
	delete p4;

	delete cPer2;
	delete cPer1;

	delete val1;
	delete val2;
	delete param;

	delete con2point;
	delete con;
	delete con2;
	delete cFix1;
	delete cH1;
	delete cV1;
}

void ParamConstraintTest::testFunction(void) {
	CPPUNIT_ASSERT_EQUAL(id,param->getId());
	CPPUNIT_ASSERT_EQUAL(value,param->getValue());

	param->setValue(value * 10);
	CPPUNIT_ASSERT_EQUAL(value*10,param->getValue());
}

void ParamConstraintTest::testFunction2(void) {
	cout << endl << "*************************" << endl;

	cout << *param;
	param->setValue(20.02);
	cout << *p1;
	cout << *p2;
	cout << *param;

	cout << *con;

	cout << "Wynik :" << con->getValue() <<  endl;

	cout << *con2point;

	cout << "Wynik :" << con2point->getValue() << endl;

	/*	try {
	 con->getValue(val1);
	 con->getNorm(val1);

	 } catch (MyException e) {

	 e.print();
	 }*/

	cout << endl << "*************************" << endl;
}
void ParamConstraintTest::testFunction3(void) {


	CPPUNIT_ASSERT_EQUAL(x*y+x*y,cPer1->getValue()(0));

	CPPUNIT_ASSERT_EQUAL(x*x+x*y,cPer2->getValue()(0));

	ublasMatrix jp=cPer1->getJacobianOnPoint(p1);
	CPPUNIT_ASSERT_EQUAL(-(2*y-y),jp(0,0));
	CPPUNIT_ASSERT_EQUAL(-(2*x-2*y),jp(0,1));


	CPPUNIT_ASSERT_EQUAL(0.0f,cFix1->getValue()(0));
	CPPUNIT_ASSERT_EQUAL(0.0f,cFix1->getValue()(1));

	cH1->getValue();
	CPPUNIT_ASSERT_EQUAL(y*x*x,cH1->getValue()(0));


	CPPUNIT_ASSERT_EQUAL(y*x*x,cV1->getValue()(0));
}

void ParamConstraintTest::testFunction4(void) {
	cout << endl << "*************************" << endl;

	cout << *cPer1;
	cout << *cPer2;

	cout << "Val1 : " << cPer1->getValue() << endl;

	cout << "Val2 : " << cPer2->getValue()<< endl;

	cout << "2JK  : " << cPer2->getJacobianOnPoint(p1) << endl;

	cout << "2JL  : " << cPer2->getJacobianOnPoint(p2) << endl;

	cout << "2M  : " << cPer2->getJacobianOnPoint(p3) << endl;

	cout << "2N  : " << cPer2->getJacobianOnPoint(p4) << endl;


	cout << "1JK  : " << cPer1->getJacobianOnPoint(p1) << endl;

	cout << "1JL  : " << cPer1->getJacobianOnPoint(p2) << endl;

	cout << "1M  : " << cPer1->getJacobianOnPoint(p3)<< endl;

	cout << "1N  : " << cPer1->getJacobianOnPoint(p4) << endl;

	cout << endl << "*************************" << endl;
}
void ParamConstraintTest::testFunction5(void) {
}
void ParamConstraintTest::testFunction6(void) {
	cout << endl << "*************************" << endl;
	cout << *cFix1 ;
	cout << *con2 ;
	cout << endl << "*************************" << endl;
}
void ParamConstraintTest::testFunction7(void) {
}
void ParamConstraintTest::testFunction8(void) {
	cout << endl << "*************************" << endl;

	cout << *cH1;

	cout << "hJK  : " << cH1->getJacobianOnPoint(p1) << endl;

	cout << "hJL  : " << cH1->getJacobianOnPoint(p3) << endl;

	cout << "hJ0  : " << cH1->getJacobianOnPoint(p2) << endl;

	cout << *cV1;

	cout << "hJK  : " << cV1->getJacobianOnPoint(p2) << endl;

	cout << "hJL  : " << cV1->getJacobianOnPoint(p4) << endl;

	cout << "hJ0  : " << cV1->getJacobianOnPoint(p3) << endl;

	cout << cFix1 ->toString() << endl;
	cout <<  cH1->toString() << endl;
	cout <<  cPer1->toString() << endl;
	cout <<  cPer2->toString() << endl;
	cout <<  cV1->toString() << endl;
	cout <<  con2point->toString() << endl;
	cout <<  param->toString() << endl;
	cout <<  p3->toString() << endl;
	cout << endl << "*************************" << endl;
}

